<template>
	<div>

		<el-dialog :close-on-click-modal="flag" :show-close="flag" title="登录" :visible.sync="$store.state.loginflag" width="30%"
		 center style="text-align: center;">
			<span>
				<div style="width: 80%;">
					账号：<el-input v-model="id" placeholder="请输入账号" maxlength=15></el-input>{{msg}}
				</div>
				<div style="width: 80%;">
					密码：<el-input v-model="pass" placeholder="请输入密码" maxlength=15 show-password size="medium"></el-input>{{msg2}}
				</div>
			</span>
			<span slot="footer" class="dialog-footer">
				<!-- <el-button @click="centerDialogVisible = false">取 消</el-button> -->
				<el-button type="primary" @click="login()" icon="el-icon-user-solid">{{bot}}</el-button>
			</span>
		</el-dialog>

	</div>


</template>

<script>
	import {
		requestLogin
	} from "network/requestLogin.js"
	export default {
		data() {
			return {
				centerDialogVisible: this.$store.state.loginflag,
				flag: false,
				id: '',
				pass: '',
				msg: '',
				msg2: '',
				bot:'登录',
				is_click:true
			};
		},
		methods: {
			login() {
				   if(this.is_click){

				if (this.id.length == 0) {
					this.msg = "不能为空"
					if (this.pass.length == 0) {
						this.msg2 = "不能为空"
					}
				} else {
					//console.log(window.localStorage.getItem('Authorization'))
					requestLogin({
						url: '/Login/admin',
						method: 'post',
						params:{
							uid:this.id,
							password:this.pass
						}
					}).then(res => {
						//	this.tableData=res
						console.log("获取成功222")
						// this.mealInfo = res.data
						if(res.data.authorization!=null&&res.data.uid!=null){
							console.log("登录成功")
						window.localStorage.setItem('authorization',res.data.authorization)
						window.localStorage.setItem('uid',res.data.uid)
						window.localStorage.setItem('admininfo',res.data.admininfo)
						this.$store.commit("updateLogin",false)
						 // console.log(window.localStorage.getItem('uid'))
						this.$router.push("blank_emt")
						 //console.log(res.data.admininfo)
						}else{
								this.bot="信息错误，重新登录"		
					setTimeout(()=>{
										this.is_click=true;
										},2000)
						}
					}).catch(err => {
						//console.log("获取失败")
						this.bot="账号格式错误，重新登录"
						setTimeout(()=>{
											this.is_click=true;
											},2000)
					})
				}
							 this.is_click=false;
				        }else{
								this.bot="频率过快，请等待..."	
									setTimeout(()=>{
									  this.is_click=true;
												 this.bot="登录"	
									},2000)
								}
			}
		}
	};
</script>

<style>
</style>
